<!-- 页面外套 -->
<div class="page-wrapper" id="personnel_train_exam">
    
    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped" id="personnel_train_exam_datagrid">

        <!-- 工具条组 -->
        <div class="tool-group">
            <div class="tool-search">
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" id="personnel_train_exam_tool_keys">
                            <option value="1">考试题目</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" id="personnel_train_exam_tool_search">
                    </div>
                </div>
                <label>
                    <span>考试类型：</span>
                    <select class="form-control" id="personnel_train_exam_tool_select1"><!--JS推进--></select>
                </label>
                <div class="im-label" id="personnel_train_exam_tool_date"><!--JS推进--></div>
                <label><button class="btn btn-primary" id="personnel_train_exam_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </div>
            <div class="tool-deal">
                <label><button class="btn btn-primary" id="personnel_train_exam_add_btn"><i class="icon icon-plus"></i> 添加</button></label>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->

    <!-- 添加盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="personnel_train_exam_add_box">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">添加</h4>
                </div>
                <div class="modal-body">
                    <form class="container">
                        <!-- 试卷信息 -->
                        <blockquote>试卷信息 <span class="small text-red">(以下均为必填项)</span></blockquote>
                        <ul class="form-checker-board">
                            <li class="col-sm-3"><label><span>试卷名称</span><input  id="personnel_train_exam_add_name"  class="form-control" type="text"></label></li>
                            <li class="col-sm-3"><label><span>考试类型</span><select id="personnel_train_exam_add_type"  class="form-control"><!-- JS推进 --></select></label></li>
                            <li class="col-sm-2"><label><span>合格分数</span><input  id="personnel_train_exam_add_score" class="form-control" type="text"></label></li>
                            <li class="col-sm-4"><label><span>考试时间</span>
                                <div class="input-group">
                                    <input id="personnel_train_exam_add_date1" class="form-control" type="text" readonly><span class="input-group-addon fix-border fix-padding"></span>
                                    <input id="personnel_train_exam_add_date2" class="form-control" type="text" readonly>
                                </div>
                            </li>
                        </ul>
                        <div class="clearfix"></div><hr>
                        <!-- 考试人员 -->
                        <blockquote>考试人员 <span class="small text-red">(以下均为必填项)</span></blockquote>
                        <ul class="tree tree-lines tree-chevrons" id="personnel_train_exam_add_tree"></ul>
                        <div class="clearfix"></div><hr>
                        <!-- 试题设置 -->
                        <blockquote>试题设置 <span class="small text-red">(提示：总分为100分，每题分数=100/题数)</span></blockquote>
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th style="width:45px;">序号</th>
                                    <th>试题</th>
                                    <th style="width:70px;">正确答案</th>
                                    <th style="width:70px;">操作</th>
                                </tr>
                            </thead>
                            <tbody class="personnel_train_exam_list" id="personnel_train_exam_add_list"><!-- JS推进 --></tbody>
                        </table>
                        <button type="button" class="btn btn-default personnel_train_exam_list_btn" id="personnel_train_exam_add_list_btn">添加试题</button>
                        <div class="clearfix"></div><hr>
                        <div class="text-center">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="personnel_train_exam_add_submit">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- personnel_train_exam_add_box -->
    
    <!-- 修改盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="personnel_train_exam_edit_box">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">修改</h4>
                </div>
                <div class="modal-body">
                    <form class="container">
                        <!-- 试卷信息 -->
                        <blockquote>试卷信息 <span class="small text-red">(以下均为必填项)</span></blockquote>
                        <ul class="form-checker-board">
                            <li class="col-sm-3"><label><span>试卷名称</span><input  id="personnel_train_exam_edit_name"  class="form-control" type="text"></label></li>
                            <li class="col-sm-3"><label><span>考试类型</span><select id="personnel_train_exam_edit_type"  class="form-control"><!-- JS推进 --></select></label></li>
                            <li class="col-sm-2"><label><span>合格分数</span><input  id="personnel_train_exam_edit_score" class="form-control" type="text"></label></li>
                            <li class="col-sm-4"><label><span>考试时间</span>
                                <div class="input-group">
                                    <input id="personnel_train_exam_edit_date1" class="form-control" type="text" readonly><span class="input-group-addon fix-border fix-padding"></span>
                                    <input id="personnel_train_exam_edit_date2" class="form-control" type="text" readonly>
                                </div>
                            </li>
                        </ul>
                        <div class="clearfix"></div><hr>
                        <!-- 考试人员 -->
                        <blockquote>考试人员 <span class="small text-red">(以下均为必填项)</span></blockquote>
                        <ul class="tree tree-lines tree-chevrons" id="personnel_train_exam_edit_tree"></ul>
                        <div class="clearfix"></div><hr>
                        <!-- 试题设置 -->
                        <blockquote>试题设置 <span class="small text-red">(提示：总分为100分，每题分数=100/题数)</span></blockquote>
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th style="width:45px;">序号</th>
                                    <th>试题</th>
                                    <th style="width:70px;">正确答案</th>
                                    <th style="width:70px;">操作</th>
                                </tr>
                            </thead>
                            <tbody class="personnel_train_exam_list" id="personnel_train_exam_edit_list"><!-- JS推进 --></tbody>
                        </table>
                        <button type="button" class="btn btn-default personnel_train_exam_list_btn" id="personnel_train_exam_edit_list_btn">添加试题</button>
                        <div class="clearfix"></div><hr>
                        <div class="text-center">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" id="personnel_train_exam_edit_submit">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- personnel_train_exam_edit_box -->

    <!-- 发布盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="personnel_train_exam_publ_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">发布</h4>
                </div>
                <div class="modal-body">
                    是否发布？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="personnel_train_exam_publ_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- personnel_train_exam_publ_box -->

    <!-- 删除盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="personnel_train_exam_dele_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <p class="text-danger"><i class="icon icon-warning-sign"></i> 是否删除？</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-danger"  id="personnel_train_exam_dele_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- personnel_train_exam_dele_box -->

</div>
<!-- page-wrapper -->

<script>
$(function(){

    //变量声明-----------------------------------------------------------------------------------------------
    var
    personnel_train_exam                    = $("#personnel_train_exam"),                     //页面ID
    personnel_train_exam_datagrid           = $("#personnel_train_exam_datagrid"),            //数据表格
    //搜索
    personnel_train_exam_tool_keys          = $("#personnel_train_exam_tool_keys"),           //搜索类别
    personnel_train_exam_tool_search        = $("#personnel_train_exam_tool_search"),         //搜索字段
    personnel_train_exam_tool_select1       = $("#personnel_train_exam_tool_select1"),        //下拉选择1
    personnel_train_exam_tool_date          = $("#personnel_train_exam_tool_date"),           //起止时间
    personnel_train_exam_search_btn         = $("#personnel_train_exam_search_btn"),          //搜索按钮
    //添加
    personnel_train_exam_add_btn            = $("#personnel_train_exam_add_btn"),             //添加按钮
    personnel_train_exam_add_box            = $("#personnel_train_exam_add_box"),             //删除盒子
    personnel_train_exam_add_name           = $("#personnel_train_exam_add_name"),            //考试名称
    personnel_train_exam_add_type           = $("#personnel_train_exam_add_type"),            //考试类型
    personnel_train_exam_add_score          = $("#personnel_train_exam_add_score"),           //合格分数
    personnel_train_exam_add_date1          = $("#personnel_train_exam_add_date1"),           //考试时间
    personnel_train_exam_add_date2          = $("#personnel_train_exam_add_date2"),           //考试时间
    personnel_train_exam_add_tree           = $("#personnel_train_exam_add_tree"),            //考试人员
    personnel_train_exam_add_list           = $("#personnel_train_exam_add_list"),            //试题设置
    personnel_train_exam_add_list_btn       = $("#personnel_train_exam_add_list_btn"),        //试题添加
    personnel_train_exam_add_submit         = $("#personnel_train_exam_add_submit"),          //删除提交
    //修改
    personnel_train_exam_edit_box           = $("#personnel_train_exam_edit_box"),            //删除盒子
    personnel_train_exam_edit_name          = $("#personnel_train_exam_edit_name"),           //考试名称
    personnel_train_exam_edit_type          = $("#personnel_train_exam_edit_type"),           //考试类型
    personnel_train_exam_edit_score         = $("#personnel_train_exam_edit_score"),          //合格分数
    personnel_train_exam_edit_date1         = $("#personnel_train_exam_edit_date1"),          //考试时间
    personnel_train_exam_edit_date2         = $("#personnel_train_exam_edit_date2"),          //考试时间
    personnel_train_exam_edit_tree          = $("#personnel_train_exam_edit_tree"),           //考试人员
    personnel_train_exam_edit_list          = $("#personnel_train_exam_edit_list"),           //试题设置
    personnel_train_exam_edit_list_btn      = $("#personnel_train_exam_edit_list_btn"),       //试题添加
    personnel_train_exam_edit_submit        = $("#personnel_train_exam_edit_submit"),         //删除提交
    //发布
    personnel_train_exam_publ_box           = $("#personnel_train_exam_publ_box"),            //发布盒子 
    personnel_train_exam_publ_submit        = $("#personnel_train_exam_publ_submit"),         //发布提交
    //删除
    personnel_train_exam_dele_box           = $("#personnel_train_exam_dele_box"),            //删除盒子 
    personnel_train_exam_dele_submit        = $("#personnel_train_exam_dele_submit");         //删除提交

    //新增&修改共用
    var
    personnel_train_exam_list       = $(".personnel_train_exam_list"),                        //试题设置
    personnel_train_exam_list_btn   = $(".personnel_train_exam_list_btn");                    //试题添加

    //接口对象-----------------------------------------------------------------------------------------------
    if( window.STATE == "local" ){

        //本地接口
        var personnel_train_exam_api = {
            datagrid  : LOCAL + "Test/Personnel/Train/exam.json",                                 //数据表格
            tree      : LOCAL + "Test/Personnel/Train/exam_staff.json",                           //考试人员
            select    : LOCAL + "Test/test_select.json",                                          //下拉选择
            edit      : LOCAL + "Test/Personnel/Train/exam_edit.json",                            //修改数据
        }

    } else if ( window.STATE == "route" ){

        //远程接口
        var personnel_train_exam_api = {
            datagrid  : LOCAL + "Test/Personnel/Train/exam.json",                                 //数据表格
            tree      : LOCAL + "Test/Personnel/Train/exam_staff.json",                           //考试人员
            select    : LOCAL + "Test/test_select.json",                                          //下拉选择
            edit      : LOCAL + "Test/Personnel/Train/exam_edit.json",                            //修改数据
        }

    }
    
    //数据表格-----------------------------------------------------------------------------------------------
    personnel_train_exam_datagrid.datagrid({
        height      : zui_datagrid_height(personnel_train_exam_datagrid),
        sortable    : false,
        cache       : false,
        showRowIndex: true,
        configs     : {
            R0:{className:"text-center"},
            C1:{className:"cell-hidden"}
        },
        states      : {
            fixedLeftUntil  : 3,
            pager           : {
                page        : 1,
                recPerPage  : window.REC_PER_PAGE,
            }
        },
        dataSource : {
            cols   : [
                {width:49,  name:"id",     label:"ID"      },
                {width:250,name:"subject", label:"考试题目"},
                {width:120,name:"type",    label:"考试类型"},
                {width:120,name:"publish", label:"发布时间"},
                {width:250,name:"examtime",label:"考试时间"},
                {width:80, name:"duration",label:"时长"    },
                {width:80, name:"state",   label:"状态"    },
                {width:180,name:"operate", label:"操作",html:true,
                    valueOperator : {
                        getter : function(dataValue,cell){
                            var temp = `
                                <a rowIndex="${cell.rowIndex}" class="personnel_train_exam_edit_btn">修改</a>
                                <a rowIndex="${cell.rowIndex}" class="personnel_train_exam_publ_btn">发布</a>
                                <a rowIndex="${cell.rowIndex}" class="personnel_train_exam_dele_btn">删除</a>
                            `;
                            return temp;
                        }
                    }
                },
            ],
            remote : function(){
                return {
                    url     : personnel_train_exam_api.datagrid,
                    type    : "POST",
                    dataType: "json",
                }
            }
        }
    });//datagrid()

    //变量声明-----------------------------------------------------------------------------------------------
    var 
    personnel_train_exam_datagrid_obj   = personnel_train_exam_datagrid.data("zui.datagrid"),   //表格对象
    personnel_train_exam_edit_btn       = ".personnel_train_exam_edit_btn",                     //修改按钮
    personnel_train_exam_publ_btn       = ".personnel_train_exam_publ_btn",                     //发布按钮
    personnel_train_exam_dele_btn       = ".personnel_train_exam_dele_btn";                     //删除按钮

    //时间组件-----------------------------------------------------------------------------------------------
    common_date_duration( personnel_train_exam_tool_date );
    personnel_train_exam_tool_date.find(".start").datetimepicker(option_date);
    personnel_train_exam_tool_date.find(".end").datetimepicker(option_date);
    personnel_train_exam_add_date1.datetimepicker( option_hour);
    personnel_train_exam_add_date2.datetimepicker( option_hour);
    personnel_train_exam_edit_date1.datetimepicker(option_hour);
    personnel_train_exam_edit_date2.datetimepicker(option_hour);

    //下拉选项-----------------------------------------------------------------------------------------------
    //考试类型
    $.ajax({
        url     : personnel_train_exam_api.select,
        type    : "post",
        dataType: "json",
        data    : {},
        success : function(data){
            if( data.status>0 ){
                var data = data.data;
                var option = "<option value='0'>全部</option>";
                for(var i=0;i<data.length;i++){
                    option += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
                }
                personnel_train_exam_tool_select1.html(option);
                personnel_train_exam_add_type.html(option);
                personnel_train_exam_edit_type.html(option);
            }         
        }
    });

    //节点树创建(添加+修改)--------------------------------------------------------------------------------
    common_tree_staff(personnel_train_exam_add_tree,false,true);       //添加
    common_tree_staff(personnel_train_exam_edit_tree,false,true);      //修改

    //试题添加删除(添加+修改)--------------------------------------------------------------------------------
    personnel_train_exam_list_append(personnel_train_exam_add_list_btn);    //试题添加(添加)
    personnel_train_exam_list_append(personnel_train_exam_edit_list_btn);   //试题添加(修改)
    personnel_train_exam_list_remove(personnel_train_exam_add_list);        //试题删除(添加)
    personnel_train_exam_list_remove(personnel_train_exam_edit_list);       //试题删除(修改)

    //搜索按钮-----------------------------------------------------------------------------------------------
    personnel_train_exam_search_btn.click(function(){

        //字段整理
        var keyword
        = "?sid=" + personnel_train_exam_tool_keys.val()
        + "&search=" + personnel_train_exam_tool_search.val()
        + "&select1="+ personnel_train_exam_tool_select1.val()
        + "&date1="  + personnel_train_exam_tool_date.find(".start").val()
        + "&date2="  + personnel_train_exam_tool_date.find(".end").val();

        //GET提交
        zui_datagrid_render(personnel_train_exam_datagrid_obj,personnel_train_exam_api.datagrid+keyword);

    });

    //添加按钮-----------------------------------------------------------------------------------------------
    personnel_train_exam_add_btn.click(function(){
        common_form_reset();                        //数据复原
        personnel_train_exam_limit = 5;             //试题设置复原
        personnel_train_exam_add_list.html("");     //试题设置复原
        personnel_train_exam_add_box.modal("show"); //面板显示
    });
    //添加提交
    personnel_train_exam_add_submit.click(function(){

        //试题name赋值
        personnel_train_exam_list_rename( personnel_train_exam_add_list );
       
        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : {
                name  : personnel_train_exam_add_name.val(),
                type  : personnel_train_exam_add_type.val(),
                score : personnel_train_exam_add_score.val(),
                date1 : personnel_train_exam_add_date1.val(),
                date2 : personnel_train_exam_add_date2.val(),
                tree  : personnel_train_exam_add_tree.attr("result"),
                list  : decodeURIComponent(personnel_train_exam_add_box.find("form").serialize(),true),
            },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(personnel_train_exam_datagrid_obj,personnel_train_exam_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //修改按钮-----------------------------------------------------------------------------------------------
    $(document).on("click",personnel_train_exam_edit_btn,function(){

        //数据ID
        var data_id  = zui_datagrid_get_id($(this).attr("rowIndex"));

        //试题设置复位
        personnel_train_exam_limit = 5;

        //远程提交
        $.ajax({
            url     : personnel_train_exam_api.edit,
            type    : "post",
            dataType: "json",
            data    : { id : data_id },
            success : function(data){
                if( data.status>0 ){
                   
                    //数据填充
                    personnel_train_exam_edit_name.val(  data.name  );
                    personnel_train_exam_edit_type.val(  data.type  );
                    personnel_train_exam_edit_score.val( data.score );
                    personnel_train_exam_edit_date1.val( data.date1 );
                    personnel_train_exam_edit_date2.val( data.date2 );
                    common_tree_staff_read(personnel_train_exam_edit_tree,data.tree);
                    //列表推进
                    var personnel_train_exam_edit_list_temp   = "";
                    var personnel_train_exam_edit_list_length = data.list.length;
                    for( var i=0;i<personnel_train_exam_edit_list_length;i++ ){ 
                        personnel_train_exam_edit_list_temp += `
                        <tr>
                            <td>${i+1}</td>
                            <td>
                                <dl>
                                    <dt><label class="input-group"><span class="input-group-addon">标题</span><input type="text" class="form-control" value="${Object.values(data.list[i])[1]}"></label></dt>
                                    <dd><label class="input-group"><span class="input-group-addon"> A  </span><input type="text" class="form-control" value="${Object.values(data.list[i])[2]}"></label></dd>
                                    <dd><label class="input-group"><span class="input-group-addon"> B  </span><input type="text" class="form-control" value="${Object.values(data.list[i])[3]}"></label></dd>
                                    <dd><label class="input-group"><span class="input-group-addon"> C  </span><input type="text" class="form-control" value="${Object.values(data.list[i])[4]}"></label></dd>
                                    <dd><label class="input-group"><span class="input-group-addon"> D  </span><input type="text" class="form-control" value="${Object.values(data.list[i])[5]}"></label></dd>
                                </dl>
                            </td>
                            <td>
                                <select class="form-control">
                                    <option value="1">A</option>
                                    <option value="2">B</option>
                                    <option value="3">C</option>
                                    <option value="4">D</option>
                                </select>
                                <input type="hidden" name="split">
                            </td>
                            <td><a>删除</a></td>
                        </tr>
                         `;
                    }
                    personnel_train_exam_edit_list.html(personnel_train_exam_edit_list_temp);

                    //option推进
                    var option = "";
                    for( var i=0;i<data.list.length;i++ ){
                        var selected = Object.values(data.list[i])[6];
                        if( selected==1 ){ option = `<option value="1" selected>A</option><option value="2">B</option><option value="3">C</option><option value="4">D</option>`; }
                        if( selected==2 ){ option = `<option value="1">A</option><option value="2" selected>B</option><option value="3">C</option><option value="4">D</option>`; }
                        if( selected==3 ){ option = `<option value="1">A</option><option value="2">B</option><option value="3" selected>C</option><option value="4">D</option>`; }
                        if( selected==4 ){ option = `<option value="1">A</option><option value="2">B</option><option value="3">C</option><option value="4" selected>D</option>`; }
                        personnel_train_exam_edit_list.find("tr").eq(i).find("select").html(option);
                    }

                    //添加按钮
                    if( personnel_train_exam_edit_list_length <= personnel_train_exam_limit ){
                        personnel_train_exam_edit_list_btn.show();
                    } else {
                        personnel_train_exam_edit_list_btn.hide();
                    }

                    //面板显示
                    personnel_train_exam_edit_submit.attr("rowIndex",data_id);
                    personnel_train_exam_edit_box.modal("show");

                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });
    //修改提交
    personnel_train_exam_edit_submit.click(function(){

        //数据ID
        var data_id = $(this).attr("rowIndex");

        //试题name赋值
        personnel_train_exam_list_rename( personnel_train_exam_edit_list );
       
        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : {
                id    : data_id,
                name  : personnel_train_exam_edit_name.val(),
                type  : personnel_train_exam_edit_type.val(),
                score : personnel_train_exam_edit_score.val(),
                date1 : personnel_train_exam_edit_date1.val(),
                date2 : personnel_train_exam_edit_date2.val(),
                tree  : personnel_train_exam_edit_tree.attr("result"),
                list  : decodeURIComponent(personnel_train_exam_edit_box.find("form").serialize(),true),
            },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(personnel_train_exam_datagrid_obj,personnel_train_exam_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //发布按钮-----------------------------------------------------------------------------------------------
    $(document).on("click",personnel_train_exam_publ_btn,function(){

        //数据ID
        var data_id = zui_datagrid_get_id($(this).attr("rowIndex"));

        //其他操作
        personnel_train_exam_publ_submit.attr("rowIndex",data_id);                              //ID传值
        personnel_train_exam_publ_box.modal("show");                                            //面板显示

    });
    //删除提交
    personnel_train_exam_publ_submit.click(function(){

        //数据ID
        var data_id = $(this).attr("rowIndex");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { id:data_id },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(personnel_train_exam_datagrid_obj,personnel_train_exam_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //删除按钮-----------------------------------------------------------------------------------------------
    $(document).on("click",personnel_train_exam_dele_btn,function(){

        //数据ID
        var data_id = zui_datagrid_get_id($(this).attr("rowIndex"));

        //其他操作
        personnel_train_exam_dele_submit.attr("rowIndex",data_id);                              //ID传值
        personnel_train_exam_dele_box.modal("show");                                            //面板显示

    });
    //删除提交
    personnel_train_exam_dele_submit.click(function(){

        //数据ID
        var data_id = $(this).attr("rowIndex");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { id:data_id },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(personnel_train_exam_datagrid_obj,personnel_train_exam_api.datagrid);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //试题添加+删除+赋值(添加+修改)----------------------------------------------------------------------------
    //试题添加
    function personnel_train_exam_list_append(selector){

        //变量声明
        var id = selector.attr("id");                                                       //操作判断
        var personnel_train_exam_list_limit = 5;                                            //数目限定
        var personnel_train_exam_list_temp  = `                                             //试题模板
            <tr>
                <td></td>
                <td>
                    <dl>
                        <dt><label class="input-group"><span class="input-group-addon">标题</span><input type="text" class="form-control"></label></dt>
                        <dd><label class="input-group"><span class="input-group-addon"> A  </span><input type="text" class="form-control"></label></dd>
                        <dd><label class="input-group"><span class="input-group-addon"> B  </span><input type="text" class="form-control"></label></dd>
                        <dd><label class="input-group"><span class="input-group-addon"> C  </span><input type="text" class="form-control"></label></dd>
                        <dd><label class="input-group"><span class="input-group-addon"> D  </span><input type="text" class="form-control"></label></dd>
                    </dl>
                </td>
                <td>
                    <select class="form-control">
                        <option value="1">A</option>
                        <option value="2">B</option>
                        <option value="3">C</option>
                        <option value="4">D</option>
                    </select>
                    <input type="hidden" name="split">
                </td>
                <td><a>删除</a></td>
            </tr>
        `;

        //点击添加
        selector.click(function(){

            //操作判断
            if( id=="personnel_train_exam_add_list_btn" ){

                //添加
                personnel_train_exam_add_list.append(personnel_train_exam_list_temp);       //试题添加
                var tr = personnel_train_exam_add_list.find("tr");                          //行号声明
                for(var i=0;i<tr.length;i++){ tr.eq(i).find("td:first-child").text( i+1 ); }//行号推进
                if( i>=personnel_train_exam_list_limit ){ um_tip("试题数目已达上限","1000","text-danger"); personnel_train_exam_add_list_btn.hide(); }

            } else if ( id=="personnel_train_exam_edit_list_btn" ){

                //修改
                personnel_train_exam_edit_list.append(personnel_train_exam_list_temp);      //试题添加
                var tr = personnel_train_exam_edit_list.find("tr");                         //行号声明
                for(var i=0;i<tr.length;i++){ tr.eq(i).find("td:first-child").text( i+1 ); }//行号推进
                if( i>=personnel_train_exam_list_limit ){ um_tip("试题数目已达上限","1000","text-danger"); personnel_train_exam_edit_list_btn.hide(); }

            }

        });

    }

    //试题删除
    function personnel_train_exam_list_remove(selector){

        //变量声明
        var id = selector.attr("id");                                                       //操作判断
        var personnel_train_exam_list_limit = 5;                                            //数目限定

        //点击删除
        selector.on("click","a",function(){

            //当前行删除
            $(this).parent().parent().remove();

            //行号推进
            for(var i=0;i<selector.find("tr").length;i++){ 
                selector.find("tr").eq(i).find("td:first-child").text( i+1 ); 
            }

            //限定解除
            if( i<=personnel_train_exam_list_limit ){ personnel_train_exam_list_btn.show(); }

        });

    }

    //试题name赋值 (返回split=则返回错误)
    function personnel_train_exam_list_rename(selector){
        selector.find("tr").each(function(i){
            var numb  = selector.find("tr").eq(i).find("td:first-child").text();   //试题序号
            var cell2 = selector.find("tr").eq(i).find("td:nth-child(2)");         //试题列
            var cell3 = selector.find("tr").eq(i).find("td:nth-child(3)");         //正确答案
            cell2.find("dt input").attr("name","tit"+numb);
            cell2.find("dd:nth-child(2) input").attr("name","opa"+numb);
            cell2.find("dd:nth-child(3) input").attr("name","opb"+numb);
            cell2.find("dd:nth-child(4) input").attr("name","opc"+numb);
            cell2.find("dd:nth-child(5) input").attr("name","opd"+numb);
            cell3.find("select").attr("name","key"+numb);
        });
    }

});//预加载结尾
</script>